Skip to content

Conversation

@SrdjanLL
Copy link
Contributor

Description

Amazon Bedrock tool use extraction logic doesn't agree with som of the use cases (conversation construction), such as the case with pre-created assistant message:

'messages': [{"role": "user", "content": "Placeholder text."}, {"role": "assistant", "content": "{"}],

This PR addresses this by adding a dict type check on the message content before attempting to get the value of tool_usefrom the content.

Fixes #3500

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • tox -e py312-test-instrumentation-botocore-0
  • Smoke tested on previously created reproducer.

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@SrdjanLL SrdjanLL requested a review from a team as a code owner May 28, 2025 09:53
@xrmx xrmx merged commit 7bd0895 into open-telemetry:main May 28, 2025
874 of 875 checks passed
liustve added a commit to aws-observability/aws-otel-python-instrumentation that referenced this pull request Jul 25, 2025
*Description of changes:*

This PR applies temporary patches to address critical bugs in the AWS
Bedrock runtime botocore instrumentation (version 0.54b0) that affect
tool use functionality in non-streaming responses reported in:
strands-agents/sdk-python#488

These changes are temporary patches and should be removed once we
upgrade to `opentelemetry-instrumentation-botocore` version 0.56b0,
which includes official fixes for these issues.

See: 
open-telemetry/opentelemetry-python-contrib#3548
open-telemetry/opentelemetry-python-contrib#3544

*Testing Done*

- Unit tests added
- Validated with Bedrock AgentCore team that fixes work.
- Ran a sample app with Bedrock AgentCore and strands framework and
validated that expected toolUse output is correct:

Before fix:

```
Tool use: {"input": ""}
Tool use: {"input": "{\"input\": 99"}
Tool use: {"input": 999}
Tool use: {"input": 99999}
Tool use: {"input": 9999}
Tool use: {"input": 9999}
Tool use: {"input": ", \"input2"}
Tool use: {"input": "\": 8"}
Tool use: {"input": 888888888888}
Tool use: {"input": 888}
Tool use: {"input": "88}"}
```

After fix:

```
Tool use: {"input": ""}
Tool use: {"input": "{\"in"}
Tool use: {"input": "put\": 9"}
Tool use: {"input": "99"}
Tool use: {"input": "99"}
Tool use: {"input": "99"}
Tool use: {"input": "9999"}
Tool use: {"input": "99999"}
Tool use: {"input": "99"}
Tool use: {"input": ", \"input"}
Tool use: {"input": "2\":"}
Tool use: {"input": " 8"}
Tool use: {"input": "888888"}
Tool use: {"input": "888888888"}
Tool use: {"input": "88}"}
```

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Noisy logs in the botocore implementation

2 participants